﻿using System;
namespace Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="xbrl_aruande_naitajad_paring", Namespace="http://producers.arireg.xtee.riik.ee/producer/arireg", Target=typeof(XbrlAruandeNaitajadParing))]
    public class XbrlAruandeNaitajadParingSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IXbrlAruandeNaitajadParing clazz;
        
        public XbrlAruandeNaitajadParingSerializer(IXbrlAruandeNaitajadParing clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            Writer.WriteStartElement("xbrl_aruande_id");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.XbrlAruandeId))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("paev_nr");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.PaevNr))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("maj_algus");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.MajAlgus))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("maj_lopp");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.MajLopp))).ToString());
            Writer.WriteEndElement();
            if (clazz.Ehak!=null) {
                Writer.WriteStartElement("ehak");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Ehak))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Aadress!=null) {
                Writer.WriteStartElement("aadress");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Aadress))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Postiind!=null) {
                Writer.WriteStartElement("postiind");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Postiind))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.PtegEmtak!=null) {
                Writer.WriteStartElement("pteg_emtak");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PtegEmtak))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.PtegEmtakVersioon!=null) {
                Writer.WriteStartElement("pteg_emtak_versioon");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.PtegEmtakVersioon))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("esitatud");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "date");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdDate(((System.DateTime)(clazz.Esitatud))).ToString());
            Writer.WriteEndElement();
            Writer.WriteStartElement("ark");
            Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
            Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Ark))).ToString());
            Writer.WriteEndElement();
            if (clazz.TootajateArv!=null) {
                Writer.WriteStartElement("tootajate_arv");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.TootajateArv))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kaive!=null) {
                Writer.WriteStartElement("kaive");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Kaive))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Kasum!=null) {
                Writer.WriteStartElement("kasum");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Kasum))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Bilansimaht!=null) {
                Writer.WriteStartElement("bilansimaht");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.Bilansimaht))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("valuuta");
            if (clazz.Valuuta!=null) {
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Valuuta))).ToString());
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : Valuuta");
            }
            Writer.WriteEndElement();
            if (clazz.EsitamiseViis!=null) {
                Writer.WriteStartElement("esitamise_viis");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.EsitamiseViis))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Auditeerimiskohustus!=null) {
                Writer.WriteStartElement("auditeerimiskohustus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Auditeerimiskohustus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Auditeeritus!=null) {
                Writer.WriteStartElement("auditeeritus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "boolean");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdBoolean(((bool)(clazz.Auditeeritus))).ToString());
                Writer.WriteEndElement();
            }
            Writer.WriteStartElement("bilansi_sisud");
            if (clazz.BilansiSisud!=null) {
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("xbrl_aruande_bilansi_sisu", "http://producers.arireg.xtee.riik.ee/producer/arireg", clazz.BilansiSisud.Count);
                for (int x = 0; ((clazz.BilansiSisud != null) 
                            && (x < clazz.BilansiSisud.Count)); x = (x + 1)) {
                    if (clazz.BilansiSisud[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaBilansiSisud = this.GetMetaData(clazz.BilansiSisud[x]);
                        Writer.WriteTypeAttribute(metaBilansiSisud.TypeQualifiedName.Namespace, metaBilansiSisud.TypeQualifiedName.Name);
                        metaBilansiSisud.NewSerializer(clazz.BilansiSisud[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException("Nullable is not allowed for element : BilansiSisud");
            }
            Writer.WriteEndElement();
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="xbrl_aruande_id") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>xbrl_aruande_id");
                }
                clazz.XbrlAruandeId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("xbrl_aruande_id")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>xbrl_aruande_id", Reader.LocalName);
            }
            if (Reader.LocalName=="paev_nr") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>paev_nr");
                }
                clazz.PaevNr = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("paev_nr")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>paev_nr", Reader.LocalName);
            }
            if (Reader.LocalName=="maj_algus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>maj_algus");
                }
                clazz.MajAlgus = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("maj_algus")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>maj_algus", Reader.LocalName);
            }
            if (Reader.LocalName=="maj_lopp") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>maj_lopp");
                }
                clazz.MajLopp = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("maj_lopp")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>maj_lopp", Reader.LocalName);
            }
            if (Reader.LocalName=="ehak") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>ehak");
                }
                clazz.Ehak = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("ehak")).Value;
            }
            if (Reader.LocalName=="aadress") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>aadress");
                }
                clazz.Aadress = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("aadress")).Value;
            }
            if (Reader.LocalName=="postiind") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>postiind");
                }
                clazz.Postiind = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("postiind")).Value;
            }
            if (Reader.LocalName=="pteg_emtak") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>pteg_emtak");
                }
                clazz.PtegEmtak = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("pteg_emtak")).Value;
            }
            if (Reader.LocalName=="pteg_emtak_versioon") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>pteg_emtak_versioon");
                }
                clazz.PtegEmtakVersioon = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("pteg_emtak_versioon")).Value;
            }
            if (Reader.LocalName=="esitatud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>esitatud");
                }
                clazz.Esitatud = new global::Xtee.Core.Schema.XsdDate(Reader.ReadElementString("esitatud")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>esitatud", Reader.LocalName);
            }
            if (Reader.LocalName=="ark") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>ark");
                }
                clazz.Ark = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ark")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>ark", Reader.LocalName);
            }
            if (Reader.LocalName=="tootajate_arv") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>tootajate_arv");
                }
                clazz.TootajateArv = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("tootajate_arv")).Value;
            }
            if (Reader.LocalName=="kaive") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>kaive");
                }
                clazz.Kaive = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kaive")).Value;
            }
            if (Reader.LocalName=="kasum") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>kasum");
                }
                clazz.Kasum = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kasum")).Value;
            }
            if (Reader.LocalName=="bilansimaht") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>bilansimaht");
                }
                clazz.Bilansimaht = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("bilansimaht")).Value;
            }
            if (Reader.LocalName=="valuuta") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>valuuta");
                }
                clazz.Valuuta = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("valuuta")).Value;
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>valuuta", Reader.LocalName);
            }
            if (Reader.LocalName=="esitamise_viis") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>esitamise_viis");
                }
                clazz.EsitamiseViis = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("esitamise_viis")).Value;
            }
            if (Reader.LocalName=="auditeerimiskohustus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>auditeerimiskohustus");
                }
                clazz.Auditeerimiskohustus = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("auditeerimiskohustus")).Value;
            }
            if (Reader.LocalName=="auditeeritus") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>auditeeritus");
                }
                clazz.Auditeeritus = new global::Xtee.Core.Schema.XsdBoolean(Reader.ReadElementString("auditeeritus")).Value;
            }
            if (Reader.LocalName=="bilansi_sisud") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_naitajad_paring>bilansi_sisud");
                }
                clazz.BilansiSisud = new System.Collections.Generic.List<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlAruandeBilansiSisu>();
                if ((Reader.IsEmptyElement == false)) {
                    Reader.ReadStartElement("bilansi_sisud");
                    for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                && (Reader.LocalName == "item")); ) {
                        if (Reader.IsElementNil()) {
                            throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>xbrl_aruande_bilansi_sisud>item");
                        }
                        global::Xtee.Core.SerializationMetadata metaBilansiSisud = this.GetMetaData<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlAruandeBilansiSisu>(Reader, "xbrl_aruande_bilansi_sisu", "http://producers.arireg.xtee.riik.ee/producer/arireg");
                        global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlAruandeBilansiSisu item = metaBilansiSisud.NewEntity<global::Producers.Arireg.Xtee.Riik.Ee.Producer.Arireg.IXbrlAruandeBilansiSisu>();
                        clazz.BilansiSisud.Add(item);
                        if ((Reader.IsEmptyElement == false)) {
                            Reader.ReadStartElement("item");
                            metaBilansiSisud.NewSerializer(item).ReadXml(Reader);
                            Reader.ReadEndElement();
                        }
                        else {
                            Reader.Skip();
                        }
                    }
                    Reader.ReadEndElement();
                }
                else {
                    Reader.Skip();
                }
            }
            else {
                throw new global::Xtee.Core.Exceptions.UnExpectedElementException(">>xbrl_aruande_naitajad_paring>bilansi_sisud", Reader.LocalName);
            }
        }
    }
}
